﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABELGX
{
    public class InfoArm : CarInfo
    {
        public Sensor Arm1 { get; set; }
        public Sensor Arm2 { get; set; }
        public Sensor Arm3 { get; set; }
        public Sensor Level { get; set; }
        public Sensor Length { get; set; }
        public Sensor Base { get; set; }
        public Sensor EndPitch { get; set; }
        public Sensor EndTurn { get; set; }
        public Sensor UnderX { get; set; }
        public Sensor UnderY { get; set; }
        List<Sensor> Sensors;
        public InfoArm(params byte[] func) : base(func)
        {
            List<SensorLevel> Levels = new List<SensorLevel>()
            {
                new SensorLevel(0, "正常", "Lime"),
                new SensorLevel(1, "告警", "Red")
            };
            Arm1 = new Sensor(new SensorSet("机械臂1角度", "°", 0.01, "f2"), Levels);
            Arm2 = new Sensor(new SensorSet("机械臂2角度", "°", 0.01, "f2"), Levels);
            Arm3 = new Sensor(new SensorSet("机械臂3角度", "°", 0.01, "f2"), Levels);
            Level = new Sensor(new SensorSet("调平角度", "°", 0.01, "f2"), Levels);
            Length = new Sensor(new SensorSet("伸缩长度", "mm", 1, "f0"), Levels);
            Base = new Sensor(new SensorSet("基座角度", "°", 0.01, "f2"), Levels);
            EndPitch = new Sensor(new SensorSet("末端俯仰", "°", 0.01, "f2"), Levels);
            EndTurn = new Sensor(new SensorSet("末端回转", "°", 0.01, "f2"), Levels);
            UnderX = new Sensor(new SensorSet("底盘X", "°", 0.01, "f2"), Levels);
            UnderY = new Sensor(new SensorSet("底盘Y", "°", 0.01, "f2"), Levels);

            Sensors = new List<Sensor>()
            { 
                Arm1, 
                Arm2,
                Arm3,
                Level,
                Length,
                Base,
                EndPitch,
                EndTurn,
                UnderX,
                UnderY
            };
        }
        public override void ProcessData(byte[] data, int start)
        {
            int i = start + 1;
            switch (data[start])
            {
                case INFO_ARM:
                    for (int j = 0; j < Sensors.Count; i += 2, j++)
                    {
                        Sensors[j].Value=BitConverter.ToInt16(data, i);
                    }
                    break;
                default:
                    break;
            }
        }

        public override void InitData()
        {
            foreach(var sensor in Sensors)
            {
                sensor.Value = 0;
            }
        }
    }
}
